<?php

###############################################################
# cPanel Addon Domain Creator 1.0
###############################################################
# Visit http://www.zubrag.com/scripts/ for updates
###############################################################
# Required parameters:
# - adomain - addon domain
# - auser - addon domain username
# - apass - addon domain password
#
# Sample run: cpanel-addon-domain.php?domain=reseller.com&auser=addon555&apass=addon12345
#
# This script can also be run from another PHP script. This may
# be helpful if you have some user interface already in place and 
# want to automatically create addon domains from there.
# In this case you have to setup following variables instead of
# passing them via url as parameters:
# - $adomain - addon domain
# - $auser - addon domain username
# - $apass - addon domain password
#
# Feel free to post your questions and comments at http://www.zubrag.com/forum/
#
###############################################################

#####################################################################################
##############        START OF SETTINGS. YOU MAY EDIT BELOW    ######################
#####################################################################################

// Cpanel username and password
$user = "bestgame";
$pass = "jjeA1xiX";
$domain = "http://server502.webhostingpad.com/cpanel"; // ex: mysite.com, 123.24.128.45

// cpanel skin. For more info on what is your skin check 
// this url      http://www.zubrag.com/articles/determine-cpanel-skin.php 
$skin = "x1";

#####################################################################################
##############          END OF SETTINGS. DO NOT EDIT BELOW    #######################
#####################################################################################

function getVar($name, $def = '') {
  if (isset($_REQUEST[$name]))
    return $_REQUEST[$name];
  else
    return $def;
}

// addon domain
if (!isset($adomain)) {
  $adomain = getVar('adomain');
}

// addon domain user
if (!isset($auser)) {
  $auser = getVar('auser');
}

// addon domain password
if (!isset($apass)) {
  $apass = getVar('apass');
}

if (empty($adomain)) {
$frm = <<<EOD
<html>
<head>
  <title>cPanel Addon Domain Creator</title>
  <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
  <META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
</head>
<body>
  <style>
    input { border: 1px solid black; }
  </style>
<form method="post">
<h3>cPanel Addon Domain Creator</h3>
<table border="0">
<tr><td>Domain:</td><td><input name="adomain" size="30"></td></tr>
<tr><td>Username:</td><td><input name="auser" size="30"></td></tr>
<tr><td>Password:</td><td><input name="apass" size="30"></td></tr>
<tr><td colspan="3"><br /><input type="submit" value="Create Addon Domain"></td></tr>
</table>
</form>
</body>
</html>
EOD;
die($frm);
}

$url = "http://$user:$pass@$domain:2082/frontend/$skin/addon/doadddomain.html?";
$url = $url . "domain=$adomain&user=$auser&pass=$apass";
$result = @file_get_contents($url);
if ($result === FALSE) die("ERROR: Addon Domain not created. Please make sure you passed correct parameters.");
echo $result;

?>